var prefix = "/nodirectList/manage";
$().ready(function() {
	validateRule();
});
$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

function onTypeChange() {
	validateRule();
}

function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : prefix + "/giveSave",
		data : $('#giveAddForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				if (data.msg) {
					parent.layer.alert(data.msg)
				}else {
					window.location.href = "/";
				}
			}

		}
	});

}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#giveAddForm").validate({
		rules : {
			midName : {
				required : true
			}
		},
		messages : {
			midName : {
				required : icon + "赠送门店不能为空"
			}
		}
	})
}

function chooseCommander() {
	layer.open({
		id:"choose_commander",
		type:2,
		title:"选择赠送门店" ,
		maxmin: true,
		shadeClose: true,
		area : [ '90%', '80%' ],
		content:"/member/manage/chooseCommander"
	})
}

//单选
function loadMemberInfo(memberId,memberName) {
	$('#mid').val(memberId);
	$('#midName').val(memberName);
	$('#isChoose').val("1");//[1:单选, 2:多选]
}

function chooseCheckCommander() {
	layer.open({
		id:"chooseCheck_commander",
		type:2,
		title:"选择赠送门店" ,
		maxmin: true,
		shadeClose: true,
		area : [ '90%', '80%' ],
		content:"/member/manage/chooseCheckCommander"
	})
}

//多选
function loadCheckMemberInfo(memberIds, memberNames) {
	$('#mids').val(memberIds);
	$('#midName').val(memberNames);
	$('#midNames').val(memberNames);
	$('#isChoose').val("2");//[1:单选, 2:多选]
}